import { useState } from 'react';

// 传入一个组件
const WithCounter = (OriginalComponent: any) => {
  // 返回组件
  const NewComponent = () => {
    // 复用的状态
    const [count, setCount] = useState(0);
    // 复用的方法
    const incrementCount = () => {
      setCount(count + 1);
    };
    return <OriginalComponent count={count} incrementCount={incrementCount} />;
  };
  return NewComponent;
};

export default WithCounter;
